package com.stylefeng.guns.config.loadBaseData;

import com.stylefeng.guns.config.redis.RedisUtil;
import com.stylefeng.guns.modular.system.model.ParamConfig;
import com.stylefeng.guns.modular.system.service.IParamConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;

@Configuration
@Slf4j
public class LoadedBaseData {

	@Autowired
	private IParamConfigService  iParamConfigService;
	
	@Autowired
	private RedisUtil redisUtil;
	
	//被@PostConstruct修饰的方法会在构造函数之后，init()方法之前运行。
	//被@PreDestroy修饰的方法会在destroy()方法之后运行，在Servlet被彻底卸载之前。
	@PostConstruct
	public  void  LoadingAreas() {
		List<ParamConfig> configs = iParamConfigService.selectList(null);
		configs.forEach(paramConfig->{
			log.info("key为：{},value为：{}",paramConfig.getKey(),paramConfig.getValue());
			redisUtil.set(paramConfig.getKey(), paramConfig.getValue());
		});
	}
	
	
}
